<?php
/*------------------------------------------
* @AUTHOR: TANDAT @EMAIL:tidusvn05@gmail.com
* @PHONE: +84933731173
* -----------------------------------------*/
class Data extends DModel {
	protected $_name = 'datas';

	protected $_primary = array('id');
	
	protected $_dependentTables = array();
	
	protected $_referenceMap    = array(
			'Keyword' => array(
					'columns'           => 'keyword_id',
					'refTableClass'     => 'Keyword',
					'refColumns'        => 'id'
			),
			'Page' => array(
					'columns'           => 'page_id',
					'refTableClass'     => 'Page',
					'refColumns'        => 'id'
			)
	
	);
	
	public function checkAndInsert($data){
		$sql = $this->select()
			->where("crawler_id =?",$data["crawler_id"])
			->where("page_id =?",$data["page_id"])
			->where("keyword_id =?",$data["keyword_id"])
			;
		$check = $this->fetchRow($sql);
		//var_dump($check->current()->url);
		if(count($check) >0){
			return $check->id;
		}else{
			return $this->insert($data);
		}
	}
	
}

?>